<!DOCTYPE html>
<html>
<head>
<title>编辑自定义表</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>编辑自定义表</h5>
            </div>
           <form id="inputForm" action="update" method="post">
           		<input type="hidden" name="id" value="#(record.id)" />
           		<input type="hidden" name="modelId" value="#(modelId)">
	            <div class="ibox-content">
	                <div class="form-horizontal clearfix">
	                	#for(modelField : modelFields)
                            #if(modelField.type=="input" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="#(modelField.name)" value="#(record.getStr(modelField.name))" class="form-control"/>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="textarea" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-8">
                                        <textarea name="#(modelField.name)" class="form-control" style="height: 250px;">#(record.getStr(modelField.name))</textarea>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="editor" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-8">
                                        <textarea name="#(modelField.name)" class="ibox-content no-padding fieldEditor" style="height: 250px;">#(record.getStr(modelField.name))</textarea>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="radio" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <div class="radio">
                                            #for(radioAttribute : modelField.fieldAttribute.radioAttributes)
                                                <label class="m-r"><input name="#(modelField.name)" value="#(radioAttribute[1])" type="radio" #if(record.getStr(modelField.name)==radioAttribute[1]) checked #end>#(radioAttribute[0])</label>
                                            #end
                                        </div>
                                    </div>
                                </div>
                            #else if(modelField.type=="checkbox" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <div class="checkbox">
                                            #for(checkboxAttribute : modelField.fieldAttribute.checkboxAttributes)
                                                <label class="m-r"><input name="#(modelField.name)" value="#(checkboxAttribute[1])" type="checkbox" #if(record.getStr(modelField.name)==checkboxAttribute[1]) checked #end>#(checkboxAttribute[0])</label>
                                            #end
                                        </div>
                                    </div>
                                </div>
                            #else if(modelField.type=="select" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <select class="form-control" name="#(modelField.name)">
                                            #for(selectAttribute : modelField.fieldAttribute.selectAttributes)
                                                <option value="#(selectAttribute[1])" #if(record.getStr(modelField.name)==selectAttribute[1]) checked #end>#(selectAttribute[0])</option>
                                            #end
                                        </select>
                                    </div>
                                </div>
                            #else if(modelField.type=="date" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="#(modelField.name)" value="#(record.getStr(modelField.name))" class="form-control Wdate" onfocus="WdatePicker({dateFmt: '#(modelField.fieldAttribute.format)'});" />
                                    </div>
                                </div>
                            #else if(modelField.type=="file" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="#(modelField.name)" value="#(record.getStr(modelField.name))" class="form-control"/>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                    <div class="col-sm-3">
                                        <a href="javascript:;" class="btn btn-primary fieldFilePicker">选择文件</a>
                                    </div>
                                </div>
                            #else if(modelField.type=="multipleFile" && modelField.isEnabled)
                               <div class="form-group" data-name="#(modelField.name)">
                                   <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                   <div class="col-sm-8">
                                       <a href="javascript:;" class="btn btn-primary fieldMultipleFilePicker">选择文件</a>
                                   </div>
                                   <div class="col-sm-3"></div>
                                   <div class="col-sm-8 multipleFile">
                                        #for(fieldValue : record.getStr(modelField.name))
                                            <div>#(fieldValue)<a href="javascript:;">[删除]</a><input type="hidden" name="#(modelField.name)" value="#(fieldValue)"/></div>
                                        #end
                                   </div>
                               </div>
                            #end
                        #end
	                </div>
	            </div>
	            <div class="modal-footer col-sm-3 col-sm-offset-2">
	                <button type="submit" class="btn btn-w-m btn-primary">确定</button>
	                <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">取消</button>
	            </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
$().ready(function() {

	var $inputForm = $("#inputForm");
	
	// 表单验证
	$inputForm.validate({
		rules: {
			#set(rulesIndex=0)
			#for(modelField : modelFields)
				#if(modelField.isEnabled && (modelField.isRequired || modelField.pattern??))
					#if(rulesIndex>0),#end #(modelField.name): {
						#if(modelField.isRequired && modelField.pattern??)
							required: true,
							pattern: #(modelField.pattern)
						#else if(modelField.isRequired)
							required: true
						#else if(modelField.pattern)
							pattern: #(modelField.pattern)
						#end
					}
					#set(rulesIndex=rulesIndex+1)
				#end
			#end
		},
		messages: {
			#set(messagesIndex=0)
			#for(modelField : modelFields)
				#if(modelField.isEnabled && modelField.pattern??)
					#if(messagesIndex>0) , #end #(modelField.name): {
						pattern: "#(modelField.alias)错误"
					}
					#set(messagesIndex=modelField+1)
				#end
			#end
		}
	});

});
</script>